package com.appwoo.txtws.activity;

import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.AsyncTask.Status;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Gallery;
import android.widget.Gallery.LayoutParams;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.TextView;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.AutoSoftInfo;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.DBHelper;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.RqSP;
import com.appwoo.txtws.service.RQNetLock;
import com.appwoo.txtws.service.RecomSoftServer;
import com.appwoo.txtws.service.SoftInfoServer;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SoftInfoActivity extends AppActivity
{
  private String apkname;
  private String apkpath;
  private ImageView app_icon;
  private AutoSoftInfo asi;
  private String author;
  private StateBean bean = new StateBean();
  private Button btnRecom;
  private Context context;
  private DownloadAsyncTask dat;
  private DBHelper dbhelper;
  private ProgressDialog dialog = null;
  private String fromParent;
  private Gallery gallery;
  private float hotMark;
  private String icon;
  private boolean isCancelDownload;
  private int isPrecd = 0;
  private int isRecd = 0;
  private Boolean isSDCard = Boolean.valueOf(false);
  private String keyid;
  private ProgressBar myProssBarhandle;
  private Boolean paused;
  private RatingBar ratingBar1;
  private String softName;
  private String softSize;
  private String softType;
  private String softid = "";
  private TextView tvContent;
  private TextView tvDesc;
  private TextView tvSoftName;
  private String updateTime;
  private String version;

  private void closeCurrentActivity()
  {
    if ((this.dat != null) && (this.dat.getStatus().equals(AsyncTask.Status.RUNNING)))
    {
      RecomAppForChildActivity.paused = Boolean.valueOf(true);
      AllAppForChildActivity.paused = Boolean.valueOf(true);
      AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.context);
      localBuilder.setIcon(2130837508);
      localBuilder.setTitle("您还有正在下载任务，确认要取消吗？");
      localBuilder.setPositiveButton(getString(2131427513), new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
        {
          SoftInfoActivity.this.paused = Boolean.valueOf(false);
          SoftInfoActivity.this.isCancelDownload = true;
          SoftInfoActivity.this.finish();
        }
      });
      localBuilder.setNegativeButton(getString(2131427514), new DialogInterface.OnClickListener()
      {
        public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
        {
          SoftInfoActivity.this.paused = Boolean.valueOf(false);
        }
      });
      localBuilder.show();
      return;
    }
    finish();
  }

  private void initActionBar()
  {
    hideBarHome();
    setBarTitle(getString(2131427346));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        SoftInfoActivity.this.closeCurrentActivity();
      }
    });
  }

  private void initView()
  {
    this.isSDCard = Boolean.valueOf(Global.isSDCard());
    this.asi = new AutoSoftInfo();
    this.dbhelper = new DBHelper(this.context);
    this.app_icon = ((ImageView)findViewById(2131493154));
    loadLogoImage(this.app_icon, this.icon, Boolean.valueOf(Global.isSDCard()));
    this.tvSoftName = ((TextView)findViewById(2131493313));
    this.tvDesc = ((TextView)findViewById(2131493315));
    this.tvContent = ((TextView)findViewById(2131493317));
    this.ratingBar1 = ((RatingBar)findViewById(2131493314));
    this.btnRecom = ((Button)findViewById(2131493156));
    this.myProssBarhandle = ((ProgressBar)findViewById(2131493072));
    this.tvSoftName.setText(this.softName);
    this.ratingBar1.setRating(this.hotMark);
    this.gallery = ((Gallery)findViewById(2131493316));
    StringBuffer localStringBuffer = new StringBuffer("类别:" + this.softType + "<br>");
    localStringBuffer.append("软件大小：" + this.softSize + "  版本：" + this.version + "<br>");
    localStringBuffer.append("更新时间：" + this.updateTime + "<br>");
    localStringBuffer.append("开发商：" + this.author);
    this.tvDesc.setText(Html.fromHtml(localStringBuffer.toString()));
    new DataTask().execute(new String[] { "installindex" });
  }

  protected void backKeyCallBack()
  {
    closeCurrentActivity();
  }

  public void onBackPressed()
  {
    closeCurrentActivity();
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903159);
    this.context = this;
    Intent localIntent = getIntent();
    this.version = localIntent.getStringExtra("version");
    this.keyid = localIntent.getStringExtra("keyid");
    this.softName = localIntent.getStringExtra("softName");
    this.apkname = localIntent.getStringExtra("apkname");
    this.author = localIntent.getStringExtra("author");
    this.hotMark = localIntent.getFloatExtra("hotMark", 3.0F);
    this.softSize = localIntent.getStringExtra("softSize");
    this.softType = localIntent.getStringExtra("softType");
    this.updateTime = localIntent.getStringExtra("updateTime");
    this.apkpath = localIntent.getStringExtra("downloadurl");
    this.icon = localIntent.getStringExtra("icon");
    logInfo(this.icon);
    this.fromParent = localIntent.getStringExtra("fromParent");
    this.isRecd = localIntent.getIntExtra("isRecd", 0);
    this.isPrecd = localIntent.getIntExtra("isPrecd", 0);
    this.paused = Boolean.valueOf(false);
    this.isCancelDownload = false;
    initActionBar();
    initView();
  }

  protected void onResume()
  {
    super.onResume();
    int i = this.btnRecom.getPaddingLeft();
    int j = this.btnRecom.getPaddingTop();
    int k = this.btnRecom.getPaddingRight();
    int m = this.btnRecom.getPaddingBottom();
    if ("1".equals(this.fromParent))
      if (this.isPrecd == 1)
      {
        this.btnRecom.setText(getResources().getString(2131427499));
        this.btnRecom.setTextColor(getResources().getColor(2131230724));
        this.btnRecom.setBackgroundDrawable(getResources().getDrawable(2130837636));
        this.btnRecom.setEnabled(false);
        this.btnRecom.setPadding(i, j, k, m);
        this.btnRecom.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            SoftInfoActivity.this.softid = SoftInfoActivity.this.keyid;
            new SoftInfoActivity.DataTask(SoftInfoActivity.this).execute(new String[] { "softRecd" });
          }
        });
      }
    while (true)
    {
      this.btnRecom.setPadding(i, j, k, m);
      return;
      this.btnRecom.setText(getResources().getString(2131427498));
      this.btnRecom.setTextColor(getResources().getColor(2131230728));
      this.btnRecom.setBackgroundDrawable(getResources().getDrawable(2130837632));
      this.btnRecom.setEnabled(true);
      break;
      if (Global.checkApkExist(this.context, this.apkname))
      {
        this.btnRecom.setText(getResources().getString(2131427501));
        this.btnRecom.setTextColor(getResources().getColor(2131230724));
        this.btnRecom.setBackgroundDrawable(getResources().getDrawable(2130837636));
        this.btnRecom.setEnabled(false);
      }
      else
      {
        this.btnRecom.setText(getResources().getString(2131427500));
        this.btnRecom.setTextColor(getResources().getColor(2131230728));
        this.btnRecom.setBackgroundDrawable(getResources().getDrawable(2130837632));
        this.btnRecom.setEnabled(true);
        this.btnRecom.setOnClickListener(new View.OnClickListener()
        {
          public void onClick(View paramAnonymousView)
          {
            Button localButton = (Button)paramAnonymousView;
            if ((!Global.isSDCard()) && (Global.getMemorySize() < 20))
            {
              SoftInfoActivity.this.alertMessage("手机空间不足，不能完成安装。");
              return;
            }
            if ((!new RQNetLock(SoftInfoActivity.this.context).getNetCmd().equals("1")) && (SoftInfoActivity.this.isNetworkAvailable(SoftInfoActivity.this.context)))
            {
              if ((localButton.getTag() == null) || ("".equals(localButton.getTag())))
              {
                localButton.setTag(SoftInfoActivity.this.apkname);
                SoftInfoActivity.this.isCancelDownload = false;
                localButton.setText("取消");
                SoftInfoActivity.this.dbhelper.insertSoftsMarket(SoftInfoActivity.this.apkname);
                SoftInfoActivity.this.myProssBarhandle.setVisibility(0);
                SoftInfoActivity.this.dat = new SoftInfoActivity.DownloadAsyncTask(SoftInfoActivity.this);
                SoftInfoActivity.DownloadAsyncTask localDownloadAsyncTask = SoftInfoActivity.this.dat;
                View[] arrayOfView = new View[2];
                arrayOfView[0] = SoftInfoActivity.this.myProssBarhandle;
                arrayOfView[1] = localButton;
                localDownloadAsyncTask.execute(arrayOfView);
                return;
              }
              SoftInfoActivity.this.isCancelDownload = true;
              localButton.setText("安装");
              localButton.setTag(null);
              SoftInfoActivity.this.myProssBarhandle.setProgress(0);
              SoftInfoActivity.this.myProssBarhandle.setVisibility(8);
              return;
            }
            SoftInfoActivity.this.alertMessage("无网络，请稍候再试");
          }
        });
      }
    }
  }

  class DataTask extends AsyncTask<String, Integer, String>
  {
    String param;

    DataTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      RqSP localRqSP = new RqSP();
      this.param = paramArrayOfString[0];
      if (this.param.equals("installindex"))
      {
        str3 = localRqSP.getChildId(SoftInfoActivity.this.context);
        SoftInfoActivity.this.asi = new SoftInfoServer(SoftInfoActivity.this.context).getSoftInfo(str3, SoftInfoActivity.this.keyid);
      }
      while (!this.param.equals("softRecd"))
      {
        String str3;
        return null;
      }
      HashMap localHashMap = new HashMap();
      localHashMap.put(SoftInfoActivity.this.softid, Integer.valueOf(1));
      String str1 = localRqSP.getLgDevAccount(SoftInfoActivity.this.context);
      String str2 = localRqSP.getLgDevId(SoftInfoActivity.this.context);
      SoftInfoActivity.this.bean = new RecomSoftServer(SoftInfoActivity.this.context).updateRecd(localHashMap, str1, str2);
      return SoftInfoActivity.this.bean.getDesc();
    }

    protected void onPostExecute(String paramString)
    {
      if (this.param.equals("installindex"))
      {
        SoftInfoActivity.this.tvContent.setText(SoftInfoActivity.this.asi.getSoftIntro());
        if ((SoftInfoActivity.this.asi != null) && (SoftInfoActivity.this.asi.getPicList() != null) && (SoftInfoActivity.this.asi.getPicList().size() > 0))
          SoftInfoActivity.this.gallery.setAdapter(new SoftInfoActivity.ImageAdapter(SoftInfoActivity.this, SoftInfoActivity.this.context, SoftInfoActivity.this.asi.getPicList()));
      }
      while (true)
      {
        SoftInfoActivity.this.dialog.dismiss();
        super.onPostExecute(paramString);
        return;
        SoftInfoActivity.this.gallery.setVisibility(8);
        continue;
        if (this.param.equals("softRecd"))
          if ("0".equals(SoftInfoActivity.this.bean.getCode()))
          {
            int i = SoftInfoActivity.this.btnRecom.getPaddingLeft();
            int j = SoftInfoActivity.this.btnRecom.getPaddingTop();
            int k = SoftInfoActivity.this.btnRecom.getPaddingRight();
            int m = SoftInfoActivity.this.btnRecom.getPaddingBottom();
            SoftInfoActivity.this.btnRecom.setText(SoftInfoActivity.this.getResources().getString(2131427499));
            SoftInfoActivity.this.btnRecom.setTextColor(SoftInfoActivity.this.getResources().getColor(2131230724));
            SoftInfoActivity.this.btnRecom.setBackgroundDrawable(SoftInfoActivity.this.getResources().getDrawable(2130837636));
            SoftInfoActivity.this.btnRecom.setPadding(i, j, k, m);
            MarketTabActivity.staASI.setIsPrecd(1);
            SoftInfoActivity.this.alertMessage(SoftInfoActivity.this.getResources().getString(2131427527));
          }
          else
          {
            SoftInfoActivity.this.alertMessage(SoftInfoActivity.this.getResources().getString(2131427528));
          }
      }
    }

    protected void onPreExecute()
    {
      if (SoftInfoActivity.this.dialog == null)
      {
        SoftInfoActivity.this.dialog = new ProgressDialog(SoftInfoActivity.this.context);
        SoftInfoActivity.this.dialog.setMessage(SoftInfoActivity.this.getString(2131427516));
        SoftInfoActivity.this.dialog.setCancelable(false);
      }
      SoftInfoActivity.this.dialog.show();
      super.onPreExecute();
    }
  }

  class DownloadAsyncTask extends AsyncTask<View, Integer, Integer>
  {
    private Button btCurrent;
    private int fileSize;
    private String filename;
    private FileOutputStream fos;
    private InputStream is;
    private String keyid;
    private ProgressBar pbCurrent;

    DownloadAsyncTask()
    {
    }

    protected Integer doInBackground(View[] paramArrayOfView)
    {
      this.pbCurrent = ((ProgressBar)paramArrayOfView[0]);
      this.btCurrent = ((Button)paramArrayOfView[1]);
      if (this.btCurrent.getTag() != null)
      {
        this.keyid = this.btCurrent.getTag().toString();
        this.filename = SoftInfoActivity.this.apkpath.substring(1 + SoftInfoActivity.this.apkpath.lastIndexOf("/"));
      }
      try
      {
        URL localURL = new URL(SoftInfoActivity.this.apkpath);
        SoftInfoActivity.this.logDebug("xjf downpath: " + Global.SOFTPATHSDCARD);
        URLConnection localURLConnection = localURL.openConnection();
        localURLConnection.connect();
        this.is = localURLConnection.getInputStream();
        this.fileSize = localURLConnection.getContentLength();
        this.pbCurrent.setMax(this.fileSize);
        if (this.fileSize <= 0)
          throw new RuntimeException(SoftInfoActivity.this.getString(2131427562));
      }
      catch (Exception localException)
      {
        this.fileSize = -1;
        localException.printStackTrace();
        SoftInfoActivity.this.logDebug("xjf" + localException.getMessage());
        return Integer.valueOf(this.fileSize);
        return Integer.valueOf(-100);
        if (this.is == null)
          throw new RuntimeException("stream is null");
      }
      finally
      {
        SoftInfoActivity.this.isCancelDownload = false;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
      }
      label319: byte[] arrayOfByte;
      int i;
      label355: int j;
      if (Global.isSDCard())
      {
        this.fos = new FileOutputStream(Global.SOFTPATHSDCARD + this.filename);
        arrayOfByte = new byte[1024];
        i = 0;
        SoftInfoActivity.this.logDebug("xjf fileSize:" + this.fileSize);
        if (SoftInfoActivity.this.paused.booleanValue())
          break label432;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(0);
        j = this.is.read(arrayOfByte);
        if (j != -1)
          break label473;
      }
      while (true)
      {
        SoftInfoActivity.this.isCancelDownload = false;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
        break;
        this.fos = SoftInfoActivity.this.context.openFileOutput(this.filename, 1);
        break label319;
        label432: SoftInfoActivity.this.logDebug("zhy paused:" + SoftInfoActivity.this.paused.toString());
        Thread.sleep(500L);
        break label355;
        label473: this.fos.write(arrayOfByte, 0, j);
        i += j;
        Integer[] arrayOfInteger = new Integer[1];
        arrayOfInteger[0] = Integer.valueOf(i);
        publishProgress(arrayOfInteger);
        if (SoftInfoActivity.this.isCancelDownload)
          this.fileSize = -1;
        boolean bool = SoftInfoActivity.this.isCancelDownload;
        if (!bool)
          break label355;
      }
    }

    protected void onPostExecute(Integer paramInteger)
    {
      this.pbCurrent.setProgress(0);
      this.pbCurrent.setVisibility(8);
      if (SoftInfoActivity.this.isCancelDownload);
      while ((this.keyid == null) || (this.keyid.length() <= 0))
        return;
      while (true)
      {
        try
        {
          Boolean localBoolean = Boolean.valueOf(Global.isSDCard());
          if (paramInteger.intValue() < 0)
            break label208;
          if (localBoolean.booleanValue())
          {
            if (paramInteger.intValue() != -1)
              Global.installApk(SoftInfoActivity.this.context, Global.SOFTPATHSDCARD + this.filename);
            if (this.is != null)
              this.is.close();
            if (this.fos == null)
              break;
            this.fos.close();
            return;
          }
        }
        catch (Exception localException)
        {
          SoftInfoActivity.this.logDebug("xjf error: " + localException.getMessage());
          return;
        }
        if (paramInteger.intValue() != -1)
        {
          Global.installApk(SoftInfoActivity.this.context, Global.SOFTPATHMEMORY + this.filename);
          continue;
          label208: paramInteger.intValue();
        }
      }
    }

    protected void onPreExecute()
    {
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      if ((this.keyid != null) && (this.keyid.length() > 0))
      {
        this.pbCurrent.setProgress(paramArrayOfInteger[0].intValue());
        ((int)(100.0F * (this.pbCurrent.getProgress() / this.pbCurrent.getMax())));
      }
    }
  }

  public class ImageAdapter extends BaseAdapter
  {
    private Context mContext;
    private List<String> mImageIds;

    public ImageAdapter(List<String> arg2)
    {
      Object localObject1;
      this.mContext = localObject1;
      Object localObject2;
      this.mImageIds = localObject2;
    }

    public int getCount()
    {
      return this.mImageIds.size();
    }

    public Object getItem(int paramInt)
    {
      return Integer.valueOf(paramInt);
    }

    public long getItemId(int paramInt)
    {
      return paramInt;
    }

    public View getView(int paramInt, View paramView, ViewGroup paramViewGroup)
    {
      ImageView localImageView = new ImageView(this.mContext);
      SoftInfoActivity.this.loadLogoImage(localImageView, (String)this.mImageIds.get(paramInt), SoftInfoActivity.this.isSDCard);
      localImageView.setScaleType(ImageView.ScaleType.FIT_XY);
      localImageView.setLayoutParams(new Gallery.LayoutParams(160, 240));
      return localImageView;
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.SoftInfoActivity
 * JD-Core Version:    0.6.2
 */